package com.sujeet.learning.xmlrpc;

import java.net.MalformedURLException;
import java.net.URL;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;

public class Client {
	
	public static void main(String [] args) {
		
		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
	    try {
			config.setServerURL(new URL("http://127.0.0.1:8083/"));
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
	    XmlRpcClient client = new XmlRpcClient();
	    client.setTransportFactory(new XmlRpcCommonsTransportFactory(client));
	    client.setConfig(config);
	    Object[] params = new Object[]{new Integer(390), new Integer(9)};
	    try {
			Integer result = (Integer) client.execute("Calculator.subtract", params);
			System.out.println(result);
		} catch (XmlRpcException e) {
			e.printStackTrace();
		}
	    Object[] params2 = new Object[]{"SUJEET"};
	    try {
			String result = (String) client.execute("Hellohandler.sayHello", params2);
			System.out.println(result);
		} catch (XmlRpcException e) {
			e.printStackTrace();
		}
	    
	}

}
